import { Form, InputNumber, Select } from 'antd';
import type { ColumnProps, ColumnsType } from 'antd/lib/table';
import type { ArtColumn } from 'ali-react-table';
import moment from 'moment';

const declareTypeOptions = [
  {
    value: '1',
    label: '买入',
  },
  {
    value: '2',
    label: '卖出',
  },
];

const columns = (disabled: boolean): ArtColumn[] => {
  return [
    {
      name: '虚拟时段',
      code: 'timeOrderName',
      align: 'center',
      lock: true,
      width: 130,
      getCellProps: (value, row, index) => {
        if (value.indexOf('汇总') > -1) {
          return {
            colSpan: 2,
          };
        }
        return {};
      },
    },
    {
      name: '时点',
      code: 'timeOrderStr',
      align: 'center',
      lock: true,
      width: 130,
    },
    {
      name: '预判',
      align: 'center',
      children: [
        {
          name: '预测出力',
          code: 'forecastPower',
          align: 'center',
          width: 100,
        },
        {
          name: '预测现货电价',
          code: 'forecastPrice',
          align: 'center',
          width: 100,
        },
      ],
    },
    {
      name: '已有持仓量',
      code: 'contractQuantity',
      align: 'center',
      width: 120,
    },
    {
      name: '偏差电量',
      code: 'deviationQuantity',
      align: 'center',
      width: 120,
    },
    {
      name: '交易限制',
      align: 'center',
      children: [
        {
          name: '可买入量',
          code: 'buyableQuantity',
          align: 'center',
          width: 120,
        },
        {
          name: '可卖出量',
          code: 'vendibilityQuantity',
          align: 'center',
          width: 120,
        },
        {
          name: '交易价格上限',
          code: 'priceUpper',
          align: 'center',
          width: 150,
        },
        {
          name: '交易价格下限',
          code: 'priceFloor',
          align: 'center',
          width: 150,
        },
      ],
    },
    {
      name: '交易策略',
      align: 'center',
      children: [
        {
          name: '交易方向',
          code: 'declareType',
          align: 'center',
          width: 120,
          render: (value, row) => {
            return (
              <Form.Item name={`declareType@${row.tableId}`}>
                <Select
                  options={declareTypeOptions}
                  size="small"
                  disabled={disabled || row.timeOrderName.indexOf('汇总') > -1}
                />
              </Form.Item>
            );
          },
        },
        {
          name: '交易价格',
          code: 'declarePrice',
          align: 'center',
          width: 120,
          render: (value, row) => {
            return (
              <Form.Item name={`declarePrice@${row.tableId}`}>
                <InputNumber
                  min={row.priceFloor}
                  max={row.priceUpper}
                  size="small"
                  precision={2}
                  disabled={disabled || row.timeOrderName.indexOf('汇总') > -1}
                />
              </Form.Item>
            );
          },
        },
        {
          name: '交易电量',
          code: 'declareQuantity',
          align: 'center',
          width: 120,
          render: (value, row) => {
            return (
              <Form.Item name={`declareQuantity@${row.tableId}`}>
                <InputNumber
                  min={0}
                  size="small"
                  precision={3}
                  disabled={disabled || row.timeOrderName.indexOf('汇总') > -1}
                />
              </Form.Item>
            );
          },
        },
      ],
    },
  ];
};

export { columns };
